<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col :md="8" :sm="24">
            <a-form-item label="类型">
              <a-select style="max-width:150px" v-model="appTypeId" placeholder="请选择" @select="TypeClick">
                <a-select-option :value="item.value" v-for="(item,index) in optionType" :key="index" >{{ item.label }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="16" :sm="24">
            <a-input-search style="max-width:450px" placeholder="请输入用户昵称关键字" @search="onSearch" >
              <a-button type="primary" slot="enterButton" icon="search">搜索</a-button>
            </a-input-search>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <s-table
      ref="table"
      size="default"
      :rowKey="(record) => record.id"
      :columns="columns"
      :data="loadData"
      :pagination="pagination"
    >
      <span slot="appName" slot-scope="text">
        <ellipsis :length="15" tooltip>{{ text }}</ellipsis>
      </span>
      <span slot="developerName" slot-scope="text">
        <ellipsis :length="15" tooltip>{{ text }}</ellipsis>
      </span>
      <span slot="appTypeName" slot-scope="text">
        <ellipsis :length="20" tooltip>{{ text }}</ellipsis>
      </span>
      <span slot="scope" slot-scope="text">
        <ellipsis :length="10" tooltip>{{ text }}</ellipsis>
      </span>
      <span slot="downloadNumber" slot-scope="text">
        <ellipsis :length="15" tooltip>{{ text }}</ellipsis>
      </span>
      <span slot="onTrialNumber" slot-scope="text">
        <ellipsis :length="15" tooltip>{{ text }}</ellipsis>
      </span>
      <span slot="addDesktopNumber" slot-scope="text">
        <ellipsis :length="10" tooltip>{{ text }}</ellipsis>
      </span>
      <span slot="commentNumber" slot-scope="text">
        <ellipsis :length="10" tooltip>{{ text }}</ellipsis>
      </span>
    </s-table>
  </a-card>
</template>

<script>
import { STable, Ellipsis } from '@/components'
import { dataList } from '@/api/data'
import utils from '@/utils/common'
import moment from 'moment'
var timeStamp = Number(new Date())

export default {
  name: 'DataCount',
  components: {
    STable,
    Ellipsis
  },
  data () {
    return {
      appTypeId: '1',
      optionType: [
        { value: '1', label: '软件' },
        { value: '2', label: '游戏' }
      ],
      // 查询参数
      queryParam: {},
      keyword: '',
      pagination: {
        current: 1,
        pageSize: 20
      },
      // 表头
      columns: [
        {
          title: '应用名称',
          dataIndex: 'appName',
          scopedSlots: { customRender: 'appName' }
        },
        {
          title: '开发商',
          dataIndex: 'developerName',
          scopedSlots: { customRender: 'developerName' }
        },
        {
          title: '类型',
          dataIndex: 'appTypeName',
          scopedSlots: { customRender: 'appTypeName' }
        },
        {
          title: '评分',
          dataIndex: 'scope',
          scopedSlots: { customRender: 'scope' }
        },
        {
          title: '下载数',
          dataIndex: 'downloadNumber',
          scopedSlots: { customRender: 'downloadNumber' }
        },
        {
          title: '试用数',
          dataIndex: 'onTrialNumber',
          scopedSlots: { customRender: 'onTrialNumber' }
        },
        {
          title: '添加数',
          dataIndex: 'addDesktopNumber',
          scopedSlots: { customRender: 'addDesktopNumber' }
        },
        {
          title: '评论数',
          dataIndex: 'commentNumber',
          scopedSlots: { customRender: 'commentNumber' }
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: pagination => {
        return dataList(Object.assign(pagination, this.queryParam)).then(res => {
          return res.data
        })
      }
    }
  },
  created () {
    this.queryParam = {
      token: utils.AuthToken(timeStamp, this.$store.getters.userKey),
      timestamp: timeStamp,
      adminId: this.$store.getters.adminId,
      keyword: this.keyword,
      appTypeId: this.appTypeId
    }
  },
  methods: {
    moment,
    TypeClick (val) { // 状态
      this.queryParam.appTypeId = val
      this.$refs.table.refresh()
    },
    onSearch (val) { // 搜索
      this.queryParam.keyword = val
      this.$refs.table.refresh()
    }
  }
}
</script>
